﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="lp_Addition_regiht_1.aspx.cs" Inherits="ZLDC.Estate.Quantify.lp_Addition_regiht_1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
        <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <link href="css/page.css" rel="stylesheet" type="text/css" />
       <script src="../js/jquery/jquery-1.3.2.js" type="text/javascript"></script>


    <script src="charts/FusionCharts.js" type="text/javascript"></script>

    <script src="charts/highcharts1.js" type="text/javascript"></script>

    <script src="js/GetUrl.js" type="text/javascript"></script>
    <script type="text/javascript">
        var depttype = '<%=depttype %>';
        var deptid = '<%=deptid %>';
        var pagedeptid = '<%=pagedeptid %>';
        window.onload = function ajaxList() {

            if (depttype == '营业大部' || depttype == '营业部' || depttype == '区域') {
                $.ajax({
                    type: "POST",
                    url: "AjaxServer.aspx",
                    dataType: 'json',
                    data: "alt=deptlist&deptid=" + deptid + "&depttype=" + depttype + "",
                    processData: false,
                    timeout: '10000',
                    success: function(msg) {
                        divlist(msg);
                       
                    },
                    error: function() {
                        document.getElementById('worklist').innerHTML = "系统繁忙";
                      
                    }

                });
            }
            else {
                document.getElementById('worklist').innerHTML = "";
                document.getElementById('divadminUrl').innerHTML = "";
            }
        }

        function divlist(msg) {

            var arr = [];
            arr.push("<table  border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce' class=\"table\" valign='top'>");
            arr.push("<tr bgcolor=\"#353c44\" >");
            arr.push("<td width=\"100px\"  style='text-align: center;background-color: #d3eaef'  >");
            arr.push("<div >部门</div>");
            arr.push("</td>");
            arr.push("<td width=\"75px\"  style='text-align: center;background-color: #d3eaef'>");
            arr.push("<div >考核人数</div>");
            arr.push("</td>");

            arr.push("<td width=\"100px\"  style='text-align: center;background-color: #d3eaef'>");
            arr.push("<div >未达标人数</div>");
            arr.push("</td>");
            arr.push("<td width=\"100px\"  style='text-align: center;background-color: #d3eaef'>");
            arr.push("<div >(经理)昨日未检查</div>");
            arr.push("</td>");
            arr.push("<td width=\"100px\"  style='text-align: center;background-color: #d3eaef'>");
            arr.push("<div >(经理)昨日未部署</div>");
            arr.push("</td>");
            arr.push("<td width=\"75px\"  style='text-align: center;background-color: #d3eaef'>");
            arr.push("<div >实际得分</div>");
            arr.push("</td>");
            arr.push("<td width=\"60px\"  style='text-align: center;background-color: #d3eaef'  >");
            arr.push("<div >平均分</div>");
            arr.push("</td>");
            arr.push("<td width=\"75px\"  style='text-align: center;background-color: #d3eaef'>");
            arr.push("<div >要求得分</div>");
            arr.push("</td>");

            arr.push("<td width=\"60px\"  style='text-align: center;background-color: #d3eaef'>");
            arr.push("<div >完成率%</div>");
            arr.push("</td>");
            arr.push("</tr>");
            var allwork_testnumber = 0; //人数
            var work_average = 0; //平均分
            var work_standard = 0;
            var work_yestoday = 0;
            var work_deployment = 0;
            var work_total = 0;
            var work_actual_goal = 0; //实际得分
            var all = 0;

            for (var i = 0; i < msg.msg.length; i++) {

                if (i % 2 == 0)
                    arr.push("<tr bgcolor='#FFFFFF'>");
                else
                    arr.push("<tr bgcolor='#EEEDED'>");
                arr.push("<td height='20' class='STYLE6'  style='text-align: center;'>");
                if (msg.depttype == '区域') {
                    if (deptid == pagedeptid) {
                        arr.push("<a onclick=\"workyestoday(" + msg.msg[i].work_deptid + ",'" + msg.msg[i].work_deptname + "')\">" + msg.msg[i].work_deptname + "</a>");
                    }
                    else {
                        arr.push(msg.msg[i].work_deptname);
                    }
                }
                else {
                    if (deptid == pagedeptid) {
                        arr.push("<a onclick=\"worklist(" + msg.msg[i].work_deptid + ",'" + msg.msg[i].work_deptname + "')\">" + msg.msg[i].work_deptname + "</a>");
                    }
                    else {
                        arr.push(msg.msg[i].work_deptname);
                    }
                   
                }
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                allwork_testnumber += parseInt(msg.msg[i].work_testnumber);
                arr.push(msg.msg[i].work_testnumber);
                arr.push("</td>");

                arr.push("<td height='20' class='STYLE6'>");
                work_standard += parseInt(msg.msg[i].work_standard);
                arr.push(msg.msg[i].work_standard);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6' style='color:red'>");
                arr.push(msg.msg[i].work_yestoday == "" ? "0" : msg.msg[i].work_yestoday);

                work_yestoday += parseInt(msg.msg[i].work_yestoday == "" ? "0" : msg.msg[i].work_yestoday);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                arr.push(msg.msg[i].work_deployment);
                work_deployment += parseInt(msg.msg[i].work_deployment);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                arr.push(msg.msg[i].work_actual_goal);
                work_total += parseInt(msg.msg[i].work_total);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                //work_average += parseInt(msg.msg[i].work_average);
                arr.push(msg.msg[i].work_average);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                arr.push(msg.msg[i].work_total);
                work_actual_goal += parseInt(msg.msg[i].work_actual_goal);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");

                if (msg.msg[i].work_total != 0) {

                    arr.push(parseInt(isNaN(((msg.msg[i].work_actual_goal * 100) / msg.msg[i].work_total)) == true ? '0' : ((msg.msg[i].work_actual_goal * 100) / msg.msg[i].work_total)));
                }
                else {
                    arr.push('0');
                }
                arr.push("</td>");
                arr.push("</tr>");
            }
            if (work_total != 0) {
                all = parseInt(isNaN(work_actual_goal * 100 / work_total) == true ? '0' : work_actual_goal * 100 / work_total);
            }
            else {
                all = 0;
            }
            arr.push("<tr  bgcolor='#FFFFFF'>");
            arr.push("<td class='STYLE6'>");
            arr.push("总计：");
            arr.push("</td>");
            arr.push("<td class='STYLE6'>");
            arr.push(allwork_testnumber);
            arr.push("</td>");
            arr.push("<td class='STYLE6'>");
            arr.push(work_standard);
            arr.push("</td>");
            arr.push("<td class='STYLE6'>");
            arr.push(isNaN(work_yestoday) == true ? "0" : work_yestoday);
            arr.push("</td>");
            arr.push("<td class='STYLE6'>");
            arr.push(work_deployment);
            arr.push("</td>");
            arr.push("<td class='STYLE6'>");
            arr.push(work_actual_goal);
            arr.push("</td>");
            arr.push("<td class='STYLE6'>");
            arr.push(changeTwoDecimal_f(work_actual_goal / allwork_testnumber));
            arr.push("</td>");
            arr.push("<td class='STYLE6'>");
            arr.push(work_total);
            arr.push("</td>");
            arr.push("<td class='STYLE6'>");
            arr.push(all);
            arr.push("</td>");
            arr.push("</tr>");
            arr.push("</table>");

            document.getElementById('worklist').innerHTML = arr.join('');
        }


        function workyestoday(deptid, deptname) {
            var today = new Date();            //月份为0-11
            var yesterday_milliseconds = today.getTime() - 1000 * 60 * 60 * 24;
            var yesterday = new Date();
            yesterday.setTime(yesterday_milliseconds);

            var strYear = yesterday.getFullYear();
            var strDay = yesterday.getDate();
            var strMonth = yesterday.getMonth() + 1;
            if (strMonth < 10) {
                strMonth = "0" + strMonth;
            }

            var strYesterday = strYear + "-" + strMonth + "-" + strDay;
            parent.closeTab( deptname);
            // self.parent.parent.addTab(deptname, "../Quantify/lp_Report_list.aspx?type=1&deptname=" + escape(deptname) + "&deptid=" + deptid + "&statrday='" + strYesterday + "'&endday='" + strYesterday + "'", "icon-nav");
            parent.addTab( deptname, "../Quantify/lp_YesterDay.aspx?type=1&deptname=" + escape(deptname) + "&deptid=" + deptid + "&statrday='" + strYesterday + "'&endday='" + strYesterday + "'", "icon-nav");
        }


        //点击区域tab
        function worklist(deptid, deptname) {
            var today = new Date();            //月份为0-11
            var yesterday_milliseconds = today.getTime() - 1000 * 60 * 60 * 24;
            var yesterday = new Date();
            yesterday.setTime(yesterday_milliseconds);

            var strYear = yesterday.getFullYear();
            var strDay = yesterday.getDate();
            var strMonth = yesterday.getMonth() + 1;
            if (strMonth < 10) {
                strMonth = "0" + strMonth;
            }

            var strYesterday = strYear + "-" + strMonth + "-" + strDay;

            parent.closeTab("昨日 " + deptname);
            parent.addTab("昨日 " + deptname, "../Quantify/Report/lp_Report_addresslist.aspx?type=1&deptname=" + escape(deptname) + "&deptid=" + deptid + "&statrday='" + strYesterday + "'&endday='" + strYesterday + "'", "icon-nav");


        }
        
        
        
        //js保留2位小数（强制）  
        function changeTwoDecimal_f(x) {
            var f_x = parseFloat(x);
            if (isNaN(f_x)) {
                //alert('function:changeTwoDecimal->parameter error');
                return false;
            }
            var f_x = Math.round(x * 100) / 100;
            var s_x = f_x.toString();
            var pos_decimal = s_x.indexOf('.');
            if (pos_decimal < 0) {
                pos_decimal = s_x.length;
                s_x += '.';
            }
            while (s_x.length <= pos_decimal + 2) {
                s_x += '0';
            }
            return s_x;
        }  
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <div style="font-size: 13px; font-weight: bold;  width: 500px" runat="server"
                        id="divdeptnum">
                        <span id="YesterDay" runat="server" style="width: 220px; float: left;"></span><span
                            style="width: 100px; float: left;" id="District" runat="server"></span><span id="Average"
                                style="width: 150px;" runat="server"></span>
                    </div>
                    <div id="worklist">
                        <img src="../images/loading.gif" />
                    </div>
                     <div id='divchart'>
                        </div><div style="width:100%;text-align:center">量化数据不包含经理人</div>
                           <script type="text/javascript">
                               if (depttype == "营业大部" || depttype == "营业部" || depttype == "区域") {
                                   $.ajax({
                                       type: "POST",
                                       url: "AjaxServer.aspx",
                                       dataType: 'json',
                                       data: "alt=chart&deptid=" + deptid + "&depttype=" + depttype + "",
                                       processData: false,
                                       timeout: '10000',
                                       success: function(msg) {
                                           chartlist(msg);
                                       },
                                       error: function() {
                                           document.getElementById('divchart').innerHTML = "系统繁忙";
                                       }

                                   });

                                   function chartlist(msg) {
                                       var chart;
                                       var yesdaychart = "";
                                       if (msg.msg.length > 0) {
                                           yesdaychart = "[";
                                           
                                           for (var i = 0; i < msg.msg.length; i++) {
                                               yesdaychart += "{name: '" + msg.msg[i].basisname + msg.msg[i].actual_number + "', y: " + msg.msg[i].actual_goal + ",dataLabels:'" + GetUrl(msg.msg[i].basisname) + "&deptid=" + deptid + "&addDate2=" + returnYesday() + "" + "&addDate1=" + returnYesday() + "'},";
                                           }
                                           
                                           yesdaychart = yesdaychart.substring(0, yesdaychart.length - 1);
                                           yesdaychart += "]";
                                           yesdaychart = eval('' + yesdaychart + '');
                                           if (deptid == pagedeptid) {
                                               chartxsDeptlist(yesdaychart, '昨日工作', 'divchart', 1);
                                           }
                                           else {
                                               chartxsDeptlist(yesdaychart, '昨日工作', 'divchart', 0);
                                           }
                                       }
                                   }
                               }
                        </script>
    </div>
    </form>
</body>
</html>
